﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace BTGame.UI
{
    class Bar : DrawableGameComponent
    {
        SpriteBatch mBatch;
        Texture2D activeBar;
        Color goodPart,badPart;
        int maxValue, barPositionX, barPositionY, widthBar, heightBar,currentValue;
        public int GeStCurrentValue
        {
            get
            {
                return currentValue;
            }
            set
            {
                currentValue = value;
            }
        }

        public Color GeStgoodPart
        {
            get
            {
                return goodPart;
            }
            set
            {
                goodPart = value;
            }
        }
        public Color GeStbadPart
        {
            get
            {
                return badPart;
            }
            set
            {
                badPart = value;
            }
        }
        public Bar(Game game,int maxValue,int barPositionX,int barPositionY,int widthBar,int heightBar): base(game)
        {
            this.maxValue = maxValue;
            this.barPositionX = barPositionX;
            this.barPositionY = barPositionY;
            this.widthBar = widthBar;
            this.heightBar = heightBar;
            currentValue = 90;
            goodPart = Color.SeaGreen;
            badPart = Color.Red;
            game.Components.Add(this);
        }
        public override void Initialize()
        {
            mBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            base.Initialize();
        }
        protected override void LoadContent()
        {
            activeBar = Game.Content.Load<Texture2D>("HealthBar");
            base.LoadContent();
        }     
        public override void Update(GameTime gameTime)
        {
           // mCurrentHealth = (int)MathHelper.Clamp(mCurrentHealth, 0, 100);
            base.Update(gameTime);
        }
        public override void Draw(GameTime gameTime)
        {
            Game.GraphicsDevice.Clear(Color.CornflowerBlue);
            mBatch.Begin();
            Rectangle source = new Rectangle(0, 45, activeBar.Width, 44);
            //Draw the negative space for the health bar
            mBatch.Draw(activeBar, new Rectangle(barPositionX,barPositionY,widthBar,heightBar), source,badPart);
            //Draw the current health level based on the current Health
            mBatch.Draw(activeBar, new Rectangle(barPositionX,barPositionY,(int)(widthBar * ((double)currentValue / maxValue)), heightBar),source, goodPart);
            //Draw the box around the health bar
              mBatch.Draw(activeBar, new Rectangle(barPositionX,barPositionY,widthBar,heightBar),
                         new Rectangle(0, 0, activeBar.Width, 44), Color.White);    
            mBatch.End();
            base.Draw(gameTime);
        }
    }
}
